home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr10 / 184_01.zip / ZIPP.C < prev    next >
Text File  |  1993-06-13  |  2KB  |  78 lines

  1. #include "libc.h"
  2.  
  3. #define TRUE -1
  4. #define FALSE 0
  5. #define MAXFILES 7
  6. /*
  7. Aztec C sets up eleven streams.  stdin, stdout, stderr are three.  One more is
  8. allowed for here to permit stdout to be redirected to a file.  This leaves
  9. seven available for zip.
  10. */
  11.  
  12. main(argc,argv)
  13. int argc; char *argv[];
  14. {
  15.     int c, i, o, was;
  16.     FILE *f[MAXFILES];    /* An array of pointers to FILE */
  17.  
  18.     if (argc < 3){
  19.         fprintf(stderr,"Usage: zip file1 file2 [file3 ... file7]\n");
  20.         fprintf(stderr,"Output is to stdout.\n");
  21.         (argc > 1 && !strcmp(argv[1],"?")) ? exit(0) : exit(1);
  22.             /* exit(1) halts any active submit */
  23.     }
  24.     if (argc > MAXFILES + 1){
  25.         fprintf(stderr,"Too many files to zip.  Eliminating %d file(s) from end of list.\n", argc - (MAXFILES + 1));
  26.         argc = MAXFILES + 1;
  27.     }
  28.  
  29.     o = argc - 1;
  30.     for (i = 0; i < argc - 1; i++){        /* open files for zipping */
  31.         if ((f[i] = fopen(argv[i+1],"r")) == NULL){
  32.             fprintf(stderr,"Bad filename: %s\n", argv[i+1]);
  33.             exit(1);
  34.         }
  35.     }
  36.  
  37.     for (;;){        /* Loop closed and broken out of later */
  38.         was = FALSE;
  39.         for (i = 0; i < argc - 1; i++){
  40.             if (f[i]){
  41.                 if ((c = agetc(f[i])) != EOF){
  42. /* If null lines are special, move to here 'if (was) putchar(' ');' */
  43.                     if (c != '\n'){
  44.                         if (was)
  45.                             putchar(' ');
  46.                         do {
  47.                             putchar(c);
  48.                             if ((c = agetc(f[i])) == EOF){
  49.                                 fclose(f[i]);
  50.                                 f[i] = NULL;
  51.                                 o--;
  52.                                 break;
  53.                             }
  54.                         } while (c != '\n');
  55.                     }
  56. /* If null lines are special, place here 'else putchar('#');' or somesuch */
  57.                     was = TRUE;
  58.                 } else {
  59.                     fclose(f[i]);
  60.                     f[i] = NULL;
  61.                     o--;
  62.                 }
  63.             }
  64.         }
  65.  
  66.         if (was)
  67.             putchar('\n');
  68.  
  69.         if (!o)        /* Break out if no more open files */
  70.             break;
  71.     }
  72. }
  73. o--;
  74.                 }
  75.             }
  76.         }
  77.  
  78.         if (w